from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time

# 指定 ChromeDriver 路径
driver_path = "D:\\桌面\\Application\\chromedriver.exe"
service = Service(driver_path)
driver = webdriver.Chrome(service=service)

# 访问京东
url = "https://www.jd.com/"
driver.get(url)

# **等待京东页面加载**
wait = WebDriverWait(driver, 10)
time.sleep(10)

# **等待并获取设备分类菜单项（家用电器）**
device = wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id='J_cate']/ul/li[1]/a")))

# **创建鼠标对象**
action = ActionChains(driver)

# **鼠标悬停到设备分类**
action.move_to_element(device).perform()

# **右键点击该元素**
action.context_click(device).perform()

# **双击该元素**
action.double_click(device).perform()

# **模拟点击该元素**
device.click()

# **等待 5 秒查看效果**
time.sleep(10)

# **关闭浏览器**
driver.quit()